function GetCPUTime(block)
%Gets CPU's internal time as a reference.
%
% %%% ZCD April 2009 %%%
%


setup(block);

%% endfunction

function setup(block)

% Register number of ports
block.NumInputPorts  = 1;
block.NumOutputPorts = 1;

% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;

% Override input port properties
block.InputPort(1).Dimensions  = 1;
block.InputPort(1).DatatypeID  = 0;  % double
block.InputPort(1).Complexity  = 'Real';
block.InputPort(1).DirectFeedthrough = true;

% Override output port properties
block.OutputPort(1).Dimensions  = 1;
block.OutputPort(1).DatatypeID  = 0; % double
block.OutputPort(1).Complexity  = 'Real';

% Register parameters
block.NumDialogPrms     = 0;

% Register sample times
%  [0 offset]            : Continuous sample time
%  [positive_num offset] : Discrete sample time
%  [-1, 0]               : Inherited sample time
%  [-2, 0]               : Variable sample time
block.SampleTimes = [-1 0];


block.RegBlockMethod('PostPropagationSetup',    @DoPostPropSetup);
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs);     % Required
block.RegBlockMethod('Update', @Update);
block.RegBlockMethod('Derivatives', @Derivatives);
block.RegBlockMethod('Terminate', @Terminate); % Required

%% end setup

function DoPostPropSetup(block)

%% end PostPropSetup

function InitializeConditions(block)
% rtTimer is a .dll code that queries the CPU clock for a time in seconds,
% not cycles, like MATLAB's cputime or the now command. rtTimer(1) sets the
% timer to t=0, and subsequent calls of rtTimer(0) return the number of
% seconds that have elapsed since the last rtTimer(1) call.
rtTimer(1);

%% end InitializeConditions

function Start(block)

%% endfunction

function Outputs(block)
% compare this with the time from the computer's CPU
block.OutputPort(1).Data(1) = rtTimer(0);

%% end Outputs

function Update(block)

%% end Update

function Derivatives(block)

%% end Derivatives

function Terminate(block)

%% end Terminate

